import datetime
import time





def get_today_time_start():
    # 获取当前日期
    today = datetime.date.today()

    # 创建一个datetime对象，时间设置为当天凌晨0点0分0秒
    midnight = datetime.datetime.combine(today, datetime.time.min)

    # 将datetime对象转换为Unix时间戳（秒）
    timestamp = int(time.mktime(midnight.timetuple()))

    return timestamp
def get_today_time_end(a =1):
    if(a!=1):
        return None
    return 86399+get_today_time_start()

def get_n_day_end_before_today(n=0):
    if(n<0):
        return None
    time = get_today_time_end()
    time = time-86400*(n)

    return time

def get_n_day_before_today(n):
    if(n<0):
        return None
    time = get_today_time_start()
    time = time-86400*(n-1)

    return time

def get_today_local_time():

    # 获取当前日期和时间
    today = datetime.datetime.today()

    # 格式化日期为 YYYYMMDD
    formatted_date = today.strftime('%Y%m%d')

    return formatted_date


def get_time_stamp(start_time_str="2024-05-22", end_time_str="2024-05-23"):
    # 给定的日期字符串
    start_time_str = start_time_str
    end_time_str = end_time_str

    # 将日期字符串转换为 datetime 对象
    start_time = datetime.datetime.strptime(start_time_str, "%Y-%m-%d")
    end_time = datetime.datetime.strptime(end_time_str, "%Y-%m-%d")

    # 将 datetime 对象转换为时间戳
    deliver_start_time = int(start_time.timestamp())
    deliver_end_time = int(end_time.timestamp())
    return deliver_start_time, deliver_end_time


def get_previous_n_days_local_time(n):
    # 获取当前日期和时间
    today = datetime.datetime.today()

    n=n-1

    # 使用timedelta计算前n天的日期
    previous_n_days = today - datetime.timedelta(days=n)

    # 格式化日期为 YYYYMMDD
    formatted_date = previous_n_days.strftime('%Y%m%d')

    return formatted_date


def get_next_n_days_local_time(n):
    # 获取当前日期和时间
    today = datetime.datetime.today()

    # 使用timedelta计算后n天的日期
    next_n_days = today + datetime.timedelta(days=n)

    # 格式化日期为 YYYYMMDD
    formatted_date = next_n_days.strftime('%Y%m%d')

    return formatted_date

